package com.heima.kafka.listener;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.User;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * 消息消费者
 */
@Component
public class HelloListener {

    @KafkaListener(topics = "qck_topic")
    public void onMessage(String message){
        if(!StringUtils.isEmpty(message)){
            System.out.println(message);
        }
    }

    @KafkaListener(topics = "user_topic")
    public void onUserMessage(String message){
        if(!StringUtils.isEmpty(message)){
            User user= JSON.parseObject(message,User.class);
            System.out.println(user.getName());
        }
    }
}
